//
//  MYongJinVC.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/4/14.
//  Copyright © 2017年 金橙云. All rights reserved.
//

#import "MYongJinVC.h"

#import "MJieSuanVC.h"
#import "MKeHuVC.h"
#import "DCNavTabBarController.h"
#import "FTPopOverMenu.h"
@interface MYongJinVC ()<UISearchBarDelegate>
{
    //全局view,好对其删除.
    UIView*view;
    //建两个全局的,来记录你点击了什么
    NSString *one;
    NSString *tow;
    NSString *keStr;
}

@property(nonatomic,strong)UISearchBar *moneySBar;
@property(nonatomic,strong)NSMutableDictionary *yongDic;

@end

@implementation MYongJinVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"销售佣金";
    
    _yongDic = [NSMutableDictionary dictionary];
    UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:nil style:UIBarButtonItemStylePlain target:self action:@selector(seacherBtnClick)];
    
    self.navigationItem.rightBarButtonItem = rightBarItem;
    [self.navigationItem.rightBarButtonItem setImage:[[UIImage imageNamed:@"Btn_seacher"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    
    MKeHuVC *keVC= [[MKeHuVC alloc] init];
    keVC.title = @"客户详情";
    
    MJieSuanVC *suanVC = [[MJieSuanVC alloc] init];
    suanVC.title = @"结算详情";
  
    
    NSArray *subViewControllers = @[keVC,suanVC];
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, LL_StatusBarAndNavigationBarHeight, B_WIDTH, 1)];
    [self.view addSubview:view];
    DCNavTabBarController *tabBarVC = [[DCNavTabBarController alloc]initWithSubViewControllers:subViewControllers];
    tabBarVC.view.frame = CGRectMake(0, 108, B_WIDTH, B_HEIGHT - 108);
    [self.view addSubview:tabBarVC.view];
    [self addChildViewController:tabBarVC];
    
    [self setSearchBar];
}

-(void)setSearchBar
{
    
    UIButton *zuoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    zuoBtn.frame = CGRectMake(0, 64, 50, 44);
    zuoBtn.backgroundColor = [UIColor colorWithHexString:@"#c9c9ca"];
    zuoBtn.titleLabel.font = [UIFont systemFontOfSize:12];
    [zuoBtn setTitle:@"  客户" forState:0];
    keStr = @"0";
    [zuoBtn setTitleColor:[UIColor blackColor] forState:0];
    [zuoBtn addTarget:self action:@selector(yongXuanBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [zuoBtn setImage:[UIImage imageNamed:@"Btn_SanJiao"] forState:0];
    [zuoBtn layoutButtonWithEdgeInsetsStyle:MKButtonEdgeInsetsStyleRight imageTitleSpace:3];
    [self.view addSubview:zuoBtn];
  

    _moneySBar = [[UISearchBar alloc] initWithFrame:CGRectMake(50, 64, B_WIDTH-50, 44)];
    _moneySBar.delegate = self;
    [_moneySBar setPlaceholder:@"请输入搜索内容"];
    [self.view addSubview:_moneySBar];
    
}

-(void)seacherBtnClick
{
    
    //    创建一个View;
    view=[[UIView alloc]initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 200)];
    view.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:view];
    
    UILabel *typeLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 8, 100, 20)];
    typeLab.font = [UIFont systemFontOfSize:12];
    typeLab.text = @"回款状态";
    [view addSubview:typeLab];
    
    //线
    for (int i = 0; i<2; i++)
    {
        UILabel *linLab = [[UILabel alloc] init];
        linLab.frame = CGRectMake(0, 62+63*i, B_WIDTH, 0.5);
        linLab.backgroundColor = [UIColor grayColor];
        [view addSubview:linLab];
    }
    NSArray *titArr= @[@"已回款",@"未回款"];
    int AA = (B_WIDTH-20*2-20)/2;
    for (int m = 0; m <2; m++)
    {
        UIButton *chengBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        chengBtn.frame = CGRectMake(20+AA*m, 35, AA-10, 20);
        chengBtn.layer.cornerRadius = 2;
        chengBtn.layer.borderWidth = 1;
        chengBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [chengBtn setTitleColor:[UIColor blackColor] forState:0];
        chengBtn.layer.borderColor = [UIColor grayColor].CGColor;
        chengBtn.tag = 1000+m;
        [chengBtn addTarget:self action:@selector(yongAddBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [chengBtn setTitle:titArr[m] forState:UIControlStateNormal];
        [view addSubview:chengBtn];
        
    }
    
    UILabel *tuiLab = [[UILabel alloc] initWithFrame:CGRectMake(10, 70, 100, 20)];
    tuiLab.font = [UIFont systemFontOfSize:12];
    tuiLab.text = @"佣金状态";
    [view addSubview:tuiLab];
    
    NSArray *titArr1= @[@"已结清",@"未结清"];
    for (int n = 0; n <2; n++)
    {
        UIButton *tuiBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        tuiBtn.frame = CGRectMake(20+AA*n, 95, AA-10, 20);
        tuiBtn.layer.cornerRadius = 2;
        tuiBtn.layer.borderWidth = 1;
        tuiBtn.titleLabel.font = [UIFont systemFontOfSize:12];
        [tuiBtn setTitleColor:[UIColor blackColor] forState:0];
        tuiBtn.layer.borderColor = [UIColor grayColor].CGColor;
        tuiBtn.tag = 1002+n;
        [tuiBtn addTarget:self action:@selector(yongAddBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        [tuiBtn setTitle:titArr1[n] forState:UIControlStateNormal];
        [view addSubview:tuiBtn];
        
    }
    
    
    //确定按钮
    
    UIButton*determineBtn=[[UIButton alloc]initWithFrame:CGRectMake(10, 145, B_WIDTH-10*2, 35)];
    determineBtn.layer.cornerRadius = 5;
    [determineBtn setTitle:@"确定" forState:UIControlStateNormal];
    [determineBtn addTarget:self action:@selector(yongSureBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    determineBtn.backgroundColor=[UIColor orangeColor];
    [view addSubview:determineBtn];
    
}
//四个按钮的点击事件,用来记录点击了什么
-(void)yongAddBtnClick:(UIButton*)btn
{
    UIButton*btn1=[self.view viewWithTag:1000];
    UIButton*btn2=[self.view viewWithTag:1001];
    UIButton*btn3=[self.view viewWithTag:1002];
    UIButton*btn4=[self.view viewWithTag:1003];
    
    if (btn.tag==1000) {
        //点击了一排第一个
        one=@"1";
        btn1.backgroundColor=[UIColor orangeColor];
        btn2.backgroundColor=[UIColor whiteColor];
    }else if (btn.tag==1001)
    { //点击了一排第二个
        one= @"2";
        btn2.backgroundColor=[UIColor orangeColor];
        btn1.backgroundColor=[UIColor whiteColor];
        
    }else if (btn.tag==1002)
    { //点击了二排第一个
        tow=@"1";
        btn3.backgroundColor=[UIColor orangeColor];
        btn4.backgroundColor=[UIColor whiteColor];
    }else if (btn.tag==1003)
    { //点击了二排第二个
        tow=@"2";
        btn4.backgroundColor=[UIColor orangeColor];
        btn3.backgroundColor=[UIColor whiteColor];
    }
    
    
}

//确定按钮的点击事件,用来掉接口
-(void)yongSureBtnClick:(UIButton *)btn
{
    NSLog(@"走这一步了没有%@---%@",one,tow);
    if (one == nil)
    {
        [_yongDic setObject:@"" forKey:@"HH"];
    }
    else if (tow == nil)
    {
        [_yongDic setObject:@"" forKey:@"GG"];
    }
    else
    {
        [_yongDic setObject:one forKey:@"HH"];
        [_yongDic setObject:tow forKey:@"GG"];
    }
    
    //NSLog(@"%@",_fangArr);
    //点击后直接进行删除view
    [view removeFromSuperview];
    
    
    //最后让两个int归零,方便下次点击继续记录
    one=@"0" ;
    tow=@"0";
    
    //第一步注册通知
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"YongJInChuan" object:_yongDic userInfo:nil];
}


-(void)yongXuanBtnClick:(UIButton *)sender
{
    NSArray *arr = @[@"客户",@"员工",];
    [FTPopOverMenu showForSender:sender
                   withMenuArray:arr
                      imageArray:nil
                       doneBlock:^(NSInteger selectedIndex)//0 . . . .
     {
         [sender setTitle:arr[selectedIndex] forState:UIControlStateNormal];
         
         NSString *yuanStr = arr[selectedIndex];
         
         if ([yuanStr isEqualToString:@"员工"])
         {
             keStr = @"1";
         }
         else
         {
             keStr = @"0";
         }
         //第一步注册通知
         NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
         [center postNotificationName:@"keHuXuan" object:keStr userInfo:nil];
         
     }
                    dismissBlock:^
     {
         
     }];
    
    
   
}


#pragma mark- 搜索的方法
- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    //第一步注册通知
    NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
    [center postNotificationName:@"YongJinSacherBar" object:searchBar.text userInfo:nil];
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
